//引入接口
import API from '../../config/server.js';

Page({
  data:{
    hero:{},
    currimg:'',
    imgList:[]
  },
  onLoad(option)
  {
    let id = option.id;
    let url = option.url;
    this.getInfo(id,url);
  },
  getInfo(id,url){
    let that = this;
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: API.herodetail,
      data: {id,url},
      header: {},
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        let data = res.data;
        if(data.success){
          // console.log(data)
          let heroDetail = data.data.heroDetail;
          let imgarr = []; 
          for (let k in heroDetail){
              if (heroDetail[k].type == 'img') {
                imgarr.push(heroDetail[k].text)
              }  
          } 
          that.setData({
            hero:data.data,
            imgList:imgarr
          })
        }

      },
      fail: function(res) {
        wx.showToast({
          title: '网络错误',
          icon: 'error'
        })
      },
      complete: function(res) {
        wx.hideLoading()  //关闭loading
      },
    })
  },
  showHistory(){
    wx.showModal({
      title: this.data.hero.historyTitle,
      content: this.data.hero.historyContent,
      showCancel: false
    })
  },
  showImg(e){
    let currimg = e.currentTarget.dataset.url;
    this.setData({
      currimg:currimg
    });
    this.previewImage();
  },
  previewImage(){
    wx.previewImage({
      current: this.data.currimg,
      urls: this.data.imgList
    })
  }
  
})